﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Movies
{
    class HelperDataStoreManager
    {

        private static String userDataDir = "\\UserData";
        
        private static String GetSeenListLocation()
        {
            String userSaveLocation = HelperSettingProvider.Default().DataStoreLocation;
            userSaveLocation = userSaveLocation + userDataDir;
            if (!Directory.Exists(userSaveLocation))
            {
                Directory.CreateDirectory(userSaveLocation);
            }
            return userSaveLocation;
        }

        private static String[] extList;

        public static String[] GetExtList()
        {
            if (extList == null)
            {
                String extListText = HelperSettingProvider.Default().ExtList;
                extList = extListText.Split(new Char[] { ',' });
            }
            return extList;
        }

        public static String[] GetSeenMovieList()
        {
            String [] seenFiles = Directory.GetFiles(GetSeenListLocation());
            return seenFiles;
        }

    

        public static bool AddSeenRecord(String movieName,String userRatting, String seenDate)
        {
            if (movieName == null)
            {
                return false;
            }
            
            try
            {
                File.WriteAllText(GetSeenListLocation() + "\\" + movieName, userRatting+","+seenDate);
            }
            catch (Exception ex)
            {
                HelperContentProvider.OmitWarning(ex);
                return false;
            }
            return true;
        }

        public static bool DeleteSeenRecord(String movieName)
        {
            if (movieName == null)
            {
                return false;
            }
            try{
                File.Delete(GetSeenListLocation() + "\\" + movieName);
            }catch(Exception ex){
                HelperContentProvider.OmitWarning(ex);
                return false;
            }
            return true;
        }

        public static bool IsExist(String movieName)
        {

            if (movieName == null)
            {
                return false;
            }

            return File.Exists((GetSeenListLocation() + "\\" + movieName));
        }


    }
}
